package jys.test.yddata.ui;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class DrawT9View extends View {
    private int line_col = Color.parseColor("#000000");

    public DrawT9View(Context context) {
        super(context);
    }

    public DrawT9View(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawT9View(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    @SuppressLint("DrawAllocation")
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        //设置画笔颜色
        paint.setColor(line_col);
        //设置圆弧的宽度
        paint.setStrokeWidth(5);
        //设置圆弧为空心
        paint.setStyle(Paint.Style.STROKE);
        //消除锯齿
        paint.setAntiAlias(true);
        //虚线
        paint.setPathEffect ( new DashPathEffect( new float [ ] { 5, 5 }, 0 ) ) ;

        int wid = getWidth();
        int hgt = getHeight();

        canvas.drawLine(0, hgt/3, wid, hgt/3, paint);
        canvas.drawLine(0, hgt*2/3, wid, hgt*2/3, paint);
        canvas.drawLine(wid/3, 0, wid/3, hgt, paint);
        canvas.drawLine(wid*2/3, 0, wid*2/3, hgt, paint);
    }
}
